//
//  ProgressIndicatorView.swift
//  SwiftUIAnimation
//
//  Created by 李煜 on 2024/8/20.
//

import SwiftUI
// 进度指示器
struct ProgressIndicatorView: View {
  @State private var progress: CGFloat = 0.0
  var body: some View {
    ZStack {
      Text("\(Int(progress * 100))%")
        .font(.system(.title, design: .rounded))
        .bold()
      Circle()
        .stroke(Color(.systemGray5), lineWidth: 10)
        .frame(width: 150, height: 150)
      Circle()
        .trim(from: 0, to: progress)
        .stroke(.green, lineWidth: 10)
        .frame(width: 150, height: 150)
        .rotationEffect(.degrees(-90))
        
    }
    .onAppear {
      Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { timer in
        self.progress += 0.05
        print(self.progress)
        if self.progress >= 1.0 {
          timer.invalidate()
        }
      }
      progress += 0.2
    }
  }
}

#Preview {
  ProgressIndicatorView()
}
